var grayId = getQueryString('grayId')
var serveName = getQueryString('serveName')


$(function () {
    var delFrontFlag = permissions.admin_sysfrontgray_del

    var options = {
        url: api + "/admin/sysfrontgray/page?sysGrayItemId="+grayId,
        updateUrl: "/pages/sysadm/gray/graySet",
        removeUrl: api + "/admin/sysfrontgray/{id}",
        createTime: false,
        modalName: "灰度",
        columns: [
            {
                title: "序号",
                formatter: function (value, row, index) {
                    return $.table.serialNumber(index);
                }
            },
            {
                field: 'frontSign',
                title: '前端唯一标识'
            },
            {
                field: 'sysDepts',
                title: '部门',
                formatter: function (value, row, index) {
                    if (value && value.length){
                        var ele = [];
                        value.forEach(function (item) {
                            ele.push('<i class="fa text-success">'+item.name+'</i>')
                        })
                        return ele
                    }
                    return ''
                }
            },
            {
                field: 'sysRoles',
                title: '角色',
                formatter: function (value, row, index) {
                    if (value && value.length){
                        var ele = [];
                        value.forEach(function (item) {
                            ele.push('<i class="fa text-info">'+item.roleName+'</i>')
                        })
                        return ele
                    }
                    return ''
                }
            },
            {
                field: 'createTime',
                title: '创建时间',
                sortable: true,
            },
            {
                title: '操作',
                align: 'center',
                formatter: function (value, row, index) {
                    var actions = [];

                    actions.push('<a class="btn btn-success btn-xs" href="javascript:void(0)" onclick="setRelation(\'' + row.id + '\',\'' + row.sysGrayItemId + '\')"><i class="fa fa-edit"></i>编辑</a> ');

                    if (delFrontFlag) {
                        actions.push('<a class="btn btn-danger btn-xs" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a> ');
                    }
                    return actions.join('');
                }
            }]
    };
    $.table.init(options);
});
function setRelation(id, grayId) {
    var url = '/pages/sysadm/gray/graySet?oper=edit&id=' + id + '&grayId=' + grayId + '&serveName='+ serveName;
    $.modal.open("设置关系", url);
}